home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / madtrb14.zip / MACHDEP.INC < prev    next >
Text File  |  1985-10-05  |  7KB  |  295 lines

  1. {This is a minimal overlay file for IBM machines and compatibles
  2.  using the addresses corresponding to COM1:. It works on a Compaq
  3.  using a Hayes Internal Modem (for sure!). The modem initialization
  4.  is for a Hayes Smartmodem. - RHM}
  5.  
  6. {NOTE: there is a routine flush in this file that
  7.  conflicts with flush in IO.INC: comment out or
  8.  delete the one in IO.INC... this one is preferred}
  9.  
  10. const
  11.   iodata    = $3f8;
  12.  
  13. procedure lineout(message: line); forward;
  14.  {lineout is in IO.INC - don't change this declaration!}
  15.  
  16. procedure clearstatus;
  17.  
  18. {Resets latching status flags on SIO chip -
  19.  replace with empty procedure if not needed}
  20.  
  21.   begin
  22.   end;
  23.  
  24. function outready: boolean;
  25.  
  26. {Returns true if serial output port is
  27.  ready to transmit a new character}
  28.  
  29.   begin
  30.     outready := ((port[$3fd] and 32) > 0);
  31.   end;
  32.  
  33. procedure xmitchar(ch: char);
  34.  
  35. {Transmits ch when serial output port is ready,
  36.    unless we're in the local mode.}
  37.  
  38.   begin
  39.     if not local then begin
  40.       repeat until outready;
  41.       port[iodata] := ord(ch);
  42.     end;
  43.   end;
  44.  
  45. function cts: boolean;
  46.  
  47. {This function returns true if a carrier tone is present on the modem
  48.  and is frequently checked to see if the caller is still present.
  49.  It always returns "true" in the local mode.}
  50.  
  51.   begin
  52.     cts := ((port[$3fe] and 128) = 128) or local;
  53.   end;
  54.  
  55. function inready: boolean;
  56.  
  57. {Returns true if we've got a character received
  58.  from the serial port or keyboard.}
  59.  
  60.   begin
  61.     inready := keypressed or ((port[$3fd] and 1) > 0);
  62.   end;
  63.  
  64. function recvchar: char;
  65.  
  66. {Returns character from serial input port,
  67.   REGARDLESS of the status of inready.}
  68.  
  69.   begin
  70.     recvchar := chr(port[iodata]);
  71.   end;
  72.  
  73. procedure setbaud(speed: rate);
  74.  
  75. {For changing the hardware baud rate setting}
  76.  
  77.   begin
  78.     port[$3fb] := 131;
  79.     case speed of
  80.       slow: begin
  81.               port[$3f8] := $80;
  82.               port[$3f9] := 1;
  83.             end;
  84.       fast: begin
  85.               port[$3f8] := $60;
  86.               port[$3f9] := $0;
  87.             end;
  88.     end;
  89.     port[$3fb] := 3;
  90.     baud := speed;
  91.   end;
  92.  
  93. procedure clearSIO;
  94.  
  95. { Initializes serial I/O chip:
  96.   sets up for 8 bits, no parity and one stop bit on both
  97.   transmit and receive, and allows character transmission
  98.   with CTS low. Also sets RTS line high. }
  99.  
  100.   begin
  101.     port[$3fb] := 3;
  102.     port[$3f9] := 0;
  103.     port[$3fc] := 11;
  104.   end;
  105.  
  106. procedure clearmodem;        (* Modem Dependent *)
  107.  
  108. {Sets modem for auto-answer, CTS line as carrier detect, no command echo}
  109.  
  110.   var buffer: line;
  111.       loop  : byte;
  112.       ch    : char;
  113.  
  114.   begin
  115.     buffer := 'ATS0=1 V0 Q1';
  116.     for loop := 1 to length(buffer) do begin
  117.       ch := buffer[loop];
  118.       xmitchar(ch);
  119.       delay(50);
  120.     end;
  121.     xmitchar(#13);
  122.     writeln;
  123.     write('Delaying...');
  124.     delay(1000); {Delays while modem digests initialization codes}
  125.     writeln;
  126.   end;
  127.  
  128. procedure setup;
  129.  
  130. {Hardware initializion for system to start BBS program}
  131.  
  132.   begin
  133.     clearSIO;
  134.     setbaud(fast);
  135.     clearmodem;
  136.   end;
  137.  
  138. function badframe: boolean;
  139.  
  140. {Indicates Framing Error on serial I/O chip - return false if not available.}
  141.  
  142.   begin
  143.     badframe := (port[$3FD] and 8) = 8;
  144.   end;
  145.  
  146. procedure dropRTS;
  147.  
  148. { Lowers RS-232 RTS line - used to inhibit auto-answer
  149.    and to cause modem to hang up }
  150.  
  151.   begin
  152.     port[$3fc] := 8;
  153.   end;
  154.  
  155. procedure raiseRTS;
  156.  
  157. (* Raises RTS line to enable auto-answer *)
  158.  
  159.   begin
  160.     port[$3fc] := 11;
  161.   end;
  162.  
  163. procedure setlocal;
  164.  
  165. {Sets local flag true and inhibits modem auto-answer}
  166.  
  167.   begin
  168.     dropRTS; {Inhibits Rixon auto-answer}
  169.     local := true;
  170.   end;
  171.  
  172. procedure clearlocal;
  173.  
  174. {Clears local flag and allows modem auto-answer}
  175.  
  176.   begin
  177.     raiseRTS; {Enables Rixon Auto-answer}
  178.     local := false;
  179.   end;
  180.  
  181. procedure unload;
  182.  
  183. {Halts Kaypro disk drives - normally they run for about 15 secs.}
  184.  
  185.   begin
  186.   end;
  187.  
  188. procedure dispcaller;
  189.  
  190. {Displays caller's name on protected 25th line of host CRT;
  191.  Replace with empty procedure if not desired.}
  192.  
  193.   begin
  194.   end;
  195.  
  196. procedure hangup;
  197.  
  198. {Signals modem to hang up - in this case by lowering RTS line for 500 msec.}
  199.  
  200.   begin
  201.     if cts then lineout('--- Disconnected ---' + cr + lf);
  202.     dropRTS;
  203.     if local then clearlocal else repeat until not cts;
  204.     raiseRTS;
  205.   end;
  206.  
  207. procedure flush;
  208.  
  209.   var junk: char;
  210.  
  211.   begin
  212.     junk := recvchar;
  213.   end;
  214.  
  215. {Real-time clock support begins here - this routine is called
  216.  even if there is NO clock, so leave it and set clockin accordingly}
  217.  
  218. procedure clock(var month,date,hour,min,sec: byte);
  219.  
  220. {Returns with month in range 1(Jan)..12(Dec),
  221.  date in 1..length of month, hour in 0..23 (24-hr clock),
  222.  minute and second in 0..59}
  223.  
  224.   var
  225.     temp: integer;
  226.     tempint: integer;
  227.     temp1: byte;
  228.  
  229.   const monthmask = $000F;
  230.         daymask = $001F;
  231.         minutemask = $003F;
  232.         secondmask = $001F;
  233.   type  dtstr = string[8];
  234.         Register        = Record
  235.                           AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer;
  236.                           End;
  237.   var  tstr : dtstr;
  238.  
  239.   function getdate : dtstr;
  240.  
  241.   var
  242.     allregs : register;
  243.     month, day,
  244.     year    : string[2];
  245.     i       : integer;
  246.     tstr    : dtstr;
  247.  
  248.   begin
  249.      allregs.ax := $2A * 256;
  250.      MsDos(allregs);
  251.      str((allregs.dx div 256):2,month);
  252.      str((allregs.dx mod 256):2,day);
  253.      str((allregs.cx - 1900):2,year);
  254.      tstr := month + '/' + day + '/' + year;
  255.      for i := 1 to 8 do
  256.        if tstr[i] = ' ' then
  257.          tstr[i] := '0';
  258.      getdate := tstr;
  259.   end;  {getdate}
  260.  
  261.   function gettime : dtstr;
  262.  
  263.   var
  264.    allregs : register;
  265.    hour, minute,
  266.    second  : string[2];
  267.    i       : integer;
  268.    tstr    : dtstr;
  269.  
  270.   begin
  271.      allregs.ax := $2C * 256;
  272.      MsDos(allregs);
  273.      str((allregs.cx div 256):2,hour);
  274.      str((allregs.cx mod 256):2,minute);
  275.      str((allregs.dx div 256):2,second);
  276.      tstr := hour + ':' + minute + ':' + second;
  277.      for i := 1 to 8 do
  278.        if tstr[i] = ' ' then
  279.          tstr[i] := '0';
  280.      gettime := tstr;
  281.   end;  {gettime}
  282.  
  283.   begin
  284.     val(copy(getdate,1,2),tempint,temp);
  285.     month := lo(tempint);
  286.     val(copy(getdate,4,2),tempint,temp);
  287.     date := lo(tempint);
  288.     val(copy(gettime,1,2),tempint,temp);
  289.     hour := lo(tempint);
  290.     val(copy(gettime,4,2),tempint,temp);
  291.     min := lo(tempint);
  292.     val(copy(gettime,7,2),tempint,temp);
  293.     sec := lo(tempint);
  294.   end;
  295.